package com.mars.kafkademo.controller;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * author by: mars
 * Date: 2020/4/7 14:10
 * Description:kafka生产者
 */
@RestController
public class KafkaSender {
    @Autowired
    private KafkaTemplate<String,String> kafkaTemplate;

//    private Gson gson = new GsonBuilder().create();

    @GetMapping("/send")
    public String send(String msg){
//        Message message = new Message();
//        message.setId(System.currentTimeMillis());
//        message.setMsg("1111");
//        message.setSendTime(new Date());
        kafkaTemplate.send("mars11",msg);
        return "ok";
    }


}
